set-option -g default-terminal 'xterm-kitty'
# set-option -g terminal-overrides ',xterm-256color:RGB'
set-option -g default-shell /usr/bin/fish

set-option -g prefix M-w

# base settings
set -g base-index 1          # start indexing windows at 1 instead of 0
set -g pane-base-index 1
set -g detach-on-destroy off # don't exit from tmux when closing a session
set -g escape-time 0         # zero-out escape time delay
set -g history-limit 100000 # increase history size (from 2,000)
set -g mouse on              # enable mouse support
set -g renumber-windows on   # renumber all windows when any window is closed
set -g set-clipboard on      # use system clipboard
set -g status-interval 3     # update the status bar every 3 seconds

# keybindings
set-window-option -g mode-keys vi
bind-key -T copy-mode-vi v send-keys -X begin-selection
bind-key -T copy-mode-vi C-v send-keys -X rectangle-toggle
bind-key -T copy-mode-vi y send-keys -X copy-selection-and-cancel bind-key -n C-F3 set-option -g status # Ctrl+F3 Combo

bind -n M-H previous-window
bind -n M-L next-window

bind '"' split-window -v -c '#{pane_current_path}'
bind % split-window -h -c '#{pane_current_path}'

bind-key x kill-pane # skip "kill-pane 1? (y/n)" prompt

is_vim="ps -o state= -o comm= -t '#{pane_tty}' | grep -iqE '^[^TXZ ]+ +(\\S+\\/)?g?(view|n?vim?x?)(diff)?$'"

bind-key -n 'C-h' if-shell "$is_vim" 'send-keys C-h' { if -F '#{pane_at_left}' '' 'select-pane -L' }
bind-key -n 'C-j' if-shell "$is_vim" 'send-keys C-j' { if -F '#{pane_at_bottom}' '' 'select-pane -D' }
bind-key -n 'C-k' if-shell "$is_vim" 'send-keys C-k' { if -F '#{pane_at_top}' '' 'select-pane -U' }
bind-key -n 'C-l' if-shell "$is_vim" 'send-keys C-l' { if -F '#{pane_at_right}' '' 'select-pane -R' }

bind-key -T copy-mode-vi 'C-h' if -F '#{pane_at_left}' '' 'select-pane -L'
bind-key -T copy-mode-vi 'C-j' if -F '#{pane_at_bottom}' '' 'select-pane -D'
bind-key -T copy-mode-vi 'C-k' if -F '#{pane_at_top}' '' 'select-pane -U'
bind-key -T copy-mode-vi 'C-l' if -F '#{pane_at_right}' '' 'selec
-pane -R'

bind -n 'M-h' if-shell "$is_vim" 'send-keys M-h' 'resize-pane -L 1'
bind -n 'M-j' if-shell "$is_vim" 'send-keys M-j' 'resize-pane -D 1'
bind -n 'M-k' if-shell "$is_vim" 'send-keys M-k' 'resize-pane -U 1'
bind -n 'M-l' if-shell "$is_vim" 'send-keys M-l' 'resize-pane -R 1'

bind-key -T copy-mode-vi M-h resize-pane -L 1
bind-key -T copy-mode-vi M-j resize-pane -D 1
bind-key -T copy-mode-vi M-k resize-pane -U 1
bind-key -T copy-mode-vi M-l resize-pane -R 1

# switch panel don't zoom out
# @link: https://superuser.com/questions/772700/switching-tmux-zoom-between-panes-without-zooming-out
bind -r o select-pane -t .+1 \;  resize-pane -Z

# ░█▀▀░▀█▀░█░░█░█░░█▀▀
# ░▀▀▄░░█░░█▄▄█░█░░█▀▀
# ░▀▀▀░░▀░░▄▄▄▀░▀▀░▀▀▀

# 1. status style
set -g status-left "#[fg=blue,bold]#S"
set -ga status-left " #[fg=white,nobold]#(gitmux -cfg $HOME/.config/tmux/gitmux.yml)"
set -g status-left-length 200    # increase length (from 10)
set -g status-position bottom       # style
set -g status-right '#{tmux_mode_indicator}'   # blank
set -g status-style 'bg=default' # transparent

set -g window-status-current-format '#[fg=pink]#W'
set -g window-status-format '#[fg=gray]#W'

# 2. message style
set -g message-command-style bg=default,fg=yellow
set -g message-style bg=default,fg=yellow
set -g mode-style bg=default,fg=yellow

# 3. window style
set -g "window-style" "bg=default"
set -g "window-active-style" "bg=default"

################################################################

# ░▄▀▀▄░█░░█░▒█░█▀▀▀░░▀░░█▀▀▄
# ░█▄▄█░█░░█░▒█░█░▀▄░░█▀░█░▒█
# ░█░░░░▀▀░░▀▀▀░▀▀▀▀░▀▀▀░▀░░▀

# 1. plugin list
set -g @plugin 'tmux-plugins/tpm'
set -g @plugin 'tmux-plugins/tmux-sensible'
set -g @plugin 'aserowy/tmux.nvim'
set -g @plugin 'tmux-plugins/tmux-yank'
set -g @plugin 'schasse/tmux-jump' # use prefix+j jump
set -g @plugin 'wfxr/tmux-fzf-url' # use prefix+u open url
set -g @plugin 'joshmedeski/t-smart-tmux-session-manager'
set -g @plugin 'tmux-plugins/tmux-copycat' 
set -g @plugin 'MunifTanjim/tmux-mode-indicator'
# prefix + ctrl-f - simple file search
# prefix + ctrl-g - jumping over git status files (best used after git status command)
# prefix + alt-h - jumping over SHA-1/SHA-256 hashes (best used after git log command)
# prefix + ctrl-u - url search (http, ftp and git urls)
# prefix + ctrl-d - number search (mnemonic d, as digit)
# prefix + alt-i - ip address search

# 2. plugin sitting
set -g @t-fzf-prompt '  '

set -g @tmux-nvim-resize-step-x 1
set -g @tmux-nvim-resize-step-y 1

# style values for prefix prompt
set -g @mode_indicator_prefix_mode_style 'bg=default,fg=red,bold'
set -g @mode_indicator_copy_mode_style 'bg=default,fg=yellow,bold'
set -g @mode_indicator_sync_mode_style 'bg=default,fg=green,bold'
set -g @mode_indicator_empty_mode_style 'bg=default,fg=blue,bold'

run '~/.tmux/plugins/tpm/tpm'

